package flyweight

import "sync"

type tMockTicketService struct {
	mTickets map[string]ITicket
	mRWMutex *sync.RWMutex
}

func newMockTicketService() *tMockTicketService {
	return &tMockTicketService{
		make(map[string]ITicket, 0),
		new(sync.RWMutex),
	}
}


func (me *tMockTicketService) Get(from string, to string) ITicket {
	k := from + "-" + to

	me.mRWMutex.RLock()
	defer me.mRWMutex.RUnlock()
	it,ok := me.mTickets[k]

	if ok {
		return it

	} else {
		return nil
	}
}


func (me *tMockTicketService) Save(it ITicket) {
	k := it.From() + "-" + it.To()

	me.mRWMutex.Lock()
	defer me.mRWMutex.Unlock()
	me.mTickets[k] = it
}


var MockTicketService ITicketService = newMockTicketService()